﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Microsoft.Data.Entity.Design.Extensibility;
using System.Xml.Linq;

namespace Liekhus.EntityFramework.XAFExtensions.CustomAttributes.Factories
{
    /// <summary>
    /// Factory used to create a Custom Entity Designer Property Extension for used in the Entity Model Designer for Size attributes
    /// </summary>
    [PartCreationPolicy(CreationPolicy.Shared)]
    [Export(typeof(IEntityDesignerExtendedProperty))]
    [EntityDesignerExtendedProperty(EntityDesignerSelection.ConceptualModelProperty)]
    class SizePropertyFactory : IEntityDesignerExtendedProperty
    {
        /// <summary>
        /// Called when the selected object in the Entity Data Model Designer changes and the new selection matches the object specified by the EntityDesignerExtendedProperty attribute.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public object CreateProperty(XElement element, PropertyExtensionContext context)
        {
            SizeProperty spSizeProp;

            spSizeProp = null;
            
            //Construct the custom SizeProperty object
            spSizeProp = new SizeProperty(element, context);
            
            //Check if the custom property should be displayed for this XElement or not
            if (spSizeProp.DisplayPropertyInEDM == false)
            {
                spSizeProp = null;
            }

            return spSizeProp;
        }
    }
}
